package com.mall.shopping.services;

import com.mall.shopping.NaviService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.PanelContentDto;
import com.mall.shopping.dto.PanelContentResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
@Component
@Service
public class NaviServiceImpl implements NaviService{

    @Autowired
    PanelContentMapper panelContentMapper;

    @Autowired
    ContentConverter contentConverter;

    @Override
    public PanelContentResponse queryPanelContent() {
        PanelContentResponse response = new PanelContentResponse();
        Example example = new Example(PanelContent.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("panelId",0);
        List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
        //类型转换
        List<PanelContentDto> panelContentDtos = contentConverter.panelContents2Dto(panelContents);
        response.setPanelContentDtoList(panelContentDtos);
        response.setCode(ShoppingRetCode.SUCCESS.getCode());
        response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return response;
    }
}
